home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / LayerMgr / Layers.p next >
Text File  |  1993-02-15  |  6KB  |  208 lines

  1. unit Layers;
  2.  
  3. {This unit was adapted to THINK Pascal 4.0 by David B. Lamkins from}
  4. {a CSMP posting by Michael Hecht, which was in turn derived from an}
  5. {earlier posting by Hugues Marty, hugues@isoftfr.isoft.fr.}
  6. {}
  7. {From:          Michael Hecht,Michael_Hecht@mac.sas.com,Internet}
  8. {}
  9. {>For a program I'm working on I'd like to be able to launch an}
  10. {>application and then "hide" it, in a manner similar to the way the OS}
  11. {>hides an app when the user chooses "Hide..." from the application menu.}
  12. {}
  13. {What you need is info on the undocumented "Layer Manager". Each}
  14. {application has a "layer" which is similar to a window. In fact, you can}
  15. {use the HideWindow and ShowWindow calls on a layer to do what you want.}
  16. {The layer's "visible" field tells you if the layer is showing or hidden.}
  17. {}
  18. {I discovered that there seems to be a layer whose elements are not}
  19. {windows, but the layers of all running processes. I called this a}
  20. {metaLayer, and discovered that a layer with the goAwayFlag set indicates}
  21. {a metaLayer. Each process' layer has this metaLayer as a parent, and this}
  22. {metaLayer has another metaLayer as its parent (I don't know why). This}
  23. {metaLayer seems to be topmost, as its parent is NIL. I called this}
  24. {topmost layer the deskLayer, since it seems to describe the entire desktop.}
  25. {}
  26. {I also found a neat routine that calls back an action proc for each}
  27. {window of each layer. I called this ForEachLayerWindowDo. I'm a bit hazy}
  28. {on the first three parameters--they seem to describe the bounds of the}
  29. {search. I think they're a starting layer, a starting window, and maybe a}
  30. {parent layer, but I'm not quite sure how they interact. It seems you're}
  31. {able to pass -1, 0, or an actual LayerPtr or WindowPtr for them.}
  32.  
  33. interface
  34.  
  35.     uses
  36.         Processes;
  37.  
  38.     type
  39.     {This records some information on the process which owns}
  40.     {the layer… Most of it is not clear (there are pointers}
  41.     {to other LayerRecords, to a heap zone, etc. in the unknown parts.}
  42.         LayerInfo = record
  43.                 unknown1: Longint;
  44.                 signature: OSType;
  45.                 creator: OSType;
  46.                 unknown2: packed array[1..24] of SignedByte;
  47.                 layerPSN: ProcessSerialNumber;
  48.                 unknown3: packed array[1..40] of SignedByte;
  49.                 moreLayerInfo: Handle;        {size = 212, contents = ?}
  50.             end;
  51.         LayerInfoPtr = ^LayerInfo;
  52.  
  53.         LayerPtr = WindowPtr;
  54.         LayerRecord = record
  55.                 port: GrafPort;                {txSize = $DEAD}
  56.                 windowKind: Integer;
  57.                 visible: Boolean;                {the layer’s visibility: HideWindow}
  58.                 hilited: Boolean;
  59.                 metaLayer: Boolean;            {a layer of layers}
  60.                 spareFlag: Boolean;
  61.                 strucRgn: RgnHandle;
  62.                 contRgn: RgnHandle;
  63.                 updateRgn: RgnHandle;
  64.                 windowDefProc: Handle;
  65.                 parentLayer: LayerPtr;        {layer of which this is a member}
  66.                 auxWinHead: AuxWinHandle;    {this layer’s AuxWinHead}
  67.                 titleWidth: Integer;
  68.                 auxCtlHead: AuxCtlHandle;    {this layer’s AuxCtlHead}
  69.                 nextLayer: LayerPtr;        {next layer in the chain}
  70.                 windowList: WindowPtr;        {this layer’s WindowList}
  71.                 layerInfo: LayerInfoPtr;        {this layer’s add' l info : GetWRefCon}
  72.             end;
  73.         LayerPeek = ^LayerRecord;
  74.  
  75.     const
  76.         kNextWindow = 0;
  77.         kNextLayer = 700;
  78.         kBreak = 701;
  79.  
  80.     type
  81.         WindowActionCode = Integer;
  82.         LayerActionProcPtr = ProcPtr;
  83. {$IFC False}
  84. {This is how the LayerActionProc is defined.}
  85.     function LayerActionProc (theWindow: WindowPtr; theLayer: LayerPtr; refCon: Longint): WindowActionCode;
  86. {$ENDC}
  87.  
  88.     const
  89.         kAllLayers = -1;
  90.  
  91. {Call the action proc for each window in each layer}
  92.     function ForEachLayerWindowDo (layer1, layer2, layer3: LayerPtr; layerAction: LayerActionProcPtr; refCon: Longint): WindowActionCode;
  93.     inline
  94.         $70F8, $A829;
  95.  
  96. {Return the window's layer}
  97.     function WindowLayer (theWindow: WindowPtr): LayerPtr;
  98.     inline
  99.         $70F9, $A829;
  100.  
  101. {Return the frontmost visible window in the given layer}
  102.     function LayerFrontVisibleWindow (theLayer: LayerPtr): WindowPtr;
  103.     inline
  104.         $70FD, $A829;
  105.  
  106. {Return the frontmost visible window on the desktop}
  107.     function DeskFrontVisibleWindow: WindowPtr;
  108.     inline
  109.         $70FE, $A829;
  110.  
  111. {Return the desktop's layer (contains all other layers)}
  112.     function DeskLayer: LayerPtr;
  113.     inline
  114.         $70FF, $A829;
  115.  
  116. {Return TRUE if theLayer is really a LayerPtr; return FALSE if it's a WindowPtr}
  117.     function IsLayer (theLayer: LayerPtr): Boolean;
  118.     inline
  119.         $7002, $A829;
  120.  
  121. {Return the current process’ layer}
  122.     function CurrentLayer: LayerPtr;
  123.     inline
  124.         $7003, $A829;
  125.  
  126. {Return the first window of this layer}
  127.     function LayerFrontWindow (theLayer: LayerPtr): WindowPtr;
  128.     inline
  129.         $7006, $A829;
  130.  
  131. {All-layer version of FindWindow}
  132.     function FindLayerWindow (where: Point; var foundWindow: WindowPtr): Integer;
  133.     inline
  134.         $7007, $A829;
  135.  
  136. {Returns true if this later is visible}
  137.     function LayerVisible (aLayer: LayerPtr): Boolean;
  138.  
  139. {Return the layer following this one}
  140.     function GetNextLayer (aLayer: LayerPtr): LayerPtr;
  141.  
  142. {Get a pointer to the layer info record for this layer}
  143.     function GetLayerInfo (aLayer: LayerPtr): LayerInfoPtr;
  144.  
  145. {Hide this layer}
  146.     procedure HideLayer (aLayer: LayerPtr);
  147.  
  148. {Show this layer}
  149.     procedure ShowLayer (aLayer: LayerPtr);
  150.  
  151. {Show or hide this layer}
  152.     procedure ShowHideLayer (aLayer: LayerPtr; showFlag: Boolean);
  153.  
  154. {Return true if this layer is hidden}
  155.     function HiddenLayer (aLayer: LayerPtr): Boolean;
  156.  
  157. {Return the name of this layer}
  158.     function GetLayerName (aLayer: LayerPtr): Str255;
  159.  
  160.  
  161. implementation
  162.  
  163.     function LayerVisible (aLayer: LayerPtr): Boolean;
  164.     begin
  165.         LayerVisible := LayerPeek(aLayer)^.visible
  166.     end; {LayerVisible}
  167.  
  168.     function GetNextLayer (aLayer: LayerPtr): LayerPtr;
  169.     begin
  170.         GetNextLayer := LayerPeek(aLayer)^.nextLayer;
  171.     end; {GetNextLayer}
  172.  
  173.     function GetLayerInfo (aLayer: LayerPtr): LayerInfoPtr;
  174.     begin
  175.         GetLayerInfo := LayerPeek(aLayer)^.layerInfo;
  176.     end; {GetLayerInfo}
  177.  
  178.     procedure HideLayer (aLayer: LayerPtr);
  179.     begin
  180.         HideWindow(WindowPtr(aLayer));
  181.     end; {HideLayer}
  182.  
  183.     procedure ShowLayer (aLayer: LayerPtr);
  184.     begin
  185.         ShowWindow(WindowPtr(aLayer));
  186.     end; {ShowLayer}
  187.  
  188.     procedure ShowHideLayer (aLayer: LayerPtr; showFlag: Boolean);
  189.     begin
  190.         ShowHide(WindowPtr(aLayer), showFlag);
  191.     end; {ShowHideLayer}
  192.  
  193.     function HiddenLayer (aLayer: LayerPtr): Boolean;
  194.     begin
  195.         HiddenLayer := not LayerPeek(aLayer)^.visible;
  196.     end; {HiddenLayer}
  197.  
  198.     function GetLayerName (aLayer: LayerPtr): Str255;
  199.         var
  200.             namePtr: StringPtr;
  201.             result: Str255;
  202.     begin
  203.         namePtr := StringPtr(ORD(GetLayerInfo(aLayer)^.moreLayerInfo^) + $38);
  204.         BlockMove(Ptr(namePtr), @result, SIZEOF(Str255));
  205.         GetLayerName := result;
  206.     end; {GetLayerName}
  207.  
  208. end.